package java8_9;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class GetAvg {
    public static void main(String[] args) {
        //输入5门课成绩，计算平均分
        Scanner in=new Scanner(System.in);
        int i=1;
        double sum=0;
        double s;//每次录入
        while(i<=5){
            System.out.println("请输入成绩：");
            s=in.nextDouble();
            if(s<0)
            {
                break;
            }

            sum+=s;
            i++;
        }
        //判断是不是提前结束了循环
        if(i>5){//正常结束
            double avg=sum/5;
            System.out.printf("平均分是:%7.1f分\n",avg);
        }else{
            System.out.println("输入错误，结束了,无法计算平均分");
        }

    }
}
